﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AAA.Algorithm.Cluster;

namespace AAA.Algorithm.Data
{
    public abstract class AbstractMapNode
    {
        private List<INeuron> _lstSample;
        private object _oKey;
        private ISimilarity _similarity;
        private int _iCurrentIteration;

        public AbstractMapNode()
        {
            Clear();
        }

        public int CurrentIteration
        {
            get { return _iCurrentIteration; }
            set { _iCurrentIteration = value; }
        }

        public object Key
        {
            get { return _oKey; }
            set { _oKey = value; }
        }

        public void Clear()
        {
            _lstSample = new List<INeuron>();
            CurrentIteration = 0;
        }

        public ISimilarity Similarity
        {
          get { return _similarity; }
          set { _similarity = value; }
        }

        public int SampleCount
        {
            get { return _lstSample.Count; }
        }

        public void AddSample(INeuron neuron)
        {
            neuron.Cluster = Key;
            _lstSample.Add(neuron);
        }

        public INeuron GetSample(int iIndex)
        {
            try
            {
                return _lstSample[iIndex];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "," + ex.StackTrace);
            }
            return null;
        }

        public void RemoveSample(INeuron neuron)
        {
            if(_lstSample.IndexOf(neuron) < 0)
                return;

            //neuron.Cluster = null;
            _lstSample.Remove(neuron);
        }

        public abstract float CalculateSimilarity(INeuron sourceNeuron);
    }
}
